﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Net;
using University.Workshop.DataAccess;
using System.Web.Security;

namespace University.Workshop.WebApp
{
    public partial class Contact : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!User.Identity.IsAuthenticated)
            {
                FormsAuthentication.RedirectToLoginPage();
            }

            txtFrom.Text = User.Identity.Name;
            txtTo.Text = "lqsadm@gmail.com";
        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage msg = new MailMessage();
                msg.To.Add(txtTo.Text);
                MailAddress address = new MailAddress("user.loquesea@gmail.com");    
                msg.From = address;   
                
                msg.Subject = User.Identity.Name + " :  " + txtSubject.Text;   
                msg.Body = txtContent.Text;

                SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
                client.EnableSsl = true; //only enable this if your provider requires it
                client.Credentials = new NetworkCredential("user.loquesea@gmail.com", "loqueseaUser");

                client.Send(msg);     
                lblStatus.Text = "Your message was sent!";   
                txtContent.Text = "";
            }
            catch
            {
                lblStatus.Text = "Your message failed to send, please try again.";
            }           

        }
    }
}